//
//  DYShopCardSetCell.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/25.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYShopCardSetCell.h"

@interface DYShopCardSetCell ()<UICollectionViewDelegate, UICollectionViewDataSource,TZImagePickerControllerDelegate>

@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)TZImagePickerController *imagePicker;


@end

@implementation DYShopCardSetCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)dy_initUI
{
    [super dy_initUI];
    
    self.sideMargin=BILIWIDTH(10);
    [self xhq_noneSelectionStyle];
    
    self.dataArray=[NSMutableArray array];
    
    self.titleLabel=({
        UILabel *label=[Utils labelWithTitleFontSize:12 textColor:[UIColor xhq_assist] alignment:0];
        label.text=@"卡片背景选择（自定义上传建议长宽比7：4）";
        label.attributedText=[DYAppCommon getRange:NSMakeRange(0, @"卡片背景选择".length) labelStr:label.text Font:label.font Color:[UIColor xhq_content]];
        label;
    });
    
    _collectionView = ({
        UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc]init];
        layout.itemSize = CGSizeMake(BILIWIDTH(114),BILIHEIGHT(65+20));
        layout.minimumInteritemSpacing =(kScreenWidth-BILIWIDTH(20+114*3))/2/2;
        layout.minimumLineSpacing =0;
        layout.headerReferenceSize = CGSizeMake(0, 0);
        //        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(BILIWIDTH(10), 0, kScreenWidth-BILIWIDTH(20), BILIHEIGHT(0))
                                                             collectionViewLayout:layout];
        collectionView.delegate = self;
        collectionView.dataSource = self;
        collectionView.pagingEnabled=YES;
        collectionView.showsHorizontalScrollIndicator=NO;
        [collectionView registerClass:[DYShopCardSetCollectionCell  class] forCellWithReuseIdentifier:@"DYShopCardSetCollectionCell"];
        
        if (@available(iOS 11.0, *)) {
            collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        collectionView.backgroundColor = [UIColor whiteColor];
        collectionView;
    });
    
    [self addSubview:self.collectionView];
    [self addSubview:self.titleLabel];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(10));
        make.top.equalTo(BILIHEIGHT(10));
    }];
    
    [self.collectionView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(10));
        make.right.equalTo(BILIWIDTH(-10));
        make.bottom.equalTo(BILIWIDTH(-1));
        make.top.equalTo(self.titleLabel.bottom).offset(BILIHEIGHT(6));
    }];
    
}

#pragma mark - UICollectionViewDataSource methods
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DYShopCardSetCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DYShopCardSetCollectionCell" forIndexPath:indexPath];
    if (indexPath.row==2) {
       cell.seletedButton.hidden=YES;
    }else{
       cell.seletedButton.hidden=NO;
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

-(void)setDataArray:(NSMutableArray *)dataArray
{
    _dataArray=dataArray;
    
    [self.collectionView reloadData];
}
-(TZImagePickerController *)imagePicker
{
    if (!_imagePicker) {
        _imagePicker=[[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        _imagePicker.preferredLanguage=@"zh-Hans";
        _imagePicker.allowPickingVideo=NO;
        _imagePicker.naviBgColor=[UIColor whiteColor];
        _imagePicker.naviTitleColor=[UIColor xhq_aTitle];
        _imagePicker.barItemTextColor=[UIColor xhq_aTitle];
        _imagePicker.showSelectBtn=YES;
    }
    return _imagePicker;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@interface DYShopCardSetCollectionCell ()

@end

@implementation DYShopCardSetCollectionCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    
    self.showImageView=({
        UIImageView *imageView=[[UIImageView alloc]init];
        [imageView xhq_cornerRadius:5];
        imageView.userInteractionEnabled=YES;
        imageView;
    });
    
    self.titleLabel=({
        UILabel *label=[Utils labelWithTitle:@"模版1" titleFontSize:12 textColor:[UIColor xhq_content] backgroundColor:WhiteColor alignment:1];
        label;
    });
    
    self.seletedButton =({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:[UIColor colorWithWhite:0 alpha:0.2] action:@selector(seletedButtonClick) target:self title:nil image:nil font:12 textColor:WhiteColor];
        [button setImage:IMG(@"icon_choose") forState:UIControlStateSelected];
        [button xhq_cornerRadius:5];
        button;
    });
    
    
    [self addSubview:self.showImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.seletedButton];
    
    [self.showImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(0);
        make.height.equalTo(BILIHEIGHT(65));
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.showImageView.bottom).offset(BILIHEIGHT(5));
    }];
    
    [self.seletedButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(0);
        make.height.equalTo(BILIHEIGHT(65));
    }];
    
    self.showImageView.image=[UIImage imageNamed:@"img_uploadpic"];
}

-(void)seletedButtonClick
{
    self.seletedButton.selected=YES;
}
@end

